//
//  CJSeeBossController.m
//  Boss
//
//  Created by admin on 2018/9/13.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJSeeBossController.h"
#import "CJCommissionCell.h"
#import "CJCommissionModel.h"
@interface CJSeeBossController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *listArray;

@property (nonatomic)NSUInteger page;

@end

@implementation CJSeeBossController
-(NSMutableArray *)listArray
{
    if (!_listArray) {
        _listArray = [[NSMutableArray alloc]init];
    }
    return _listArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    [self setupUI];
    [self loadShareList];
    WEAKSELF
    self.tableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //weakSelf.refresh=NO;
        weakSelf.page++;
        // [weakSelf loadTableData];
        [weakSelf loadShareList];
    }];
}

-(void)loadShareList
{
    WEAKSELF
    [WYHttpServer getCommissionShareListWithBusinessId:self.businessId WithCurrenPage:@"1" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf.listArray addObjectsFromArray:[CJCommissionModel getCommissionModelArrayFromJson:response[@"result"][@"detail"]]];
            [weakSelf.tableView reloadData];
            if ([response[@"result"][@"hasNextPage"] integerValue]) {
                [weakSelf.tableView.mj_footer endRefreshing];
                
                
                
            }else{
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
    }];
}


-(void)setupUI
{
    self.navigationItem.title = @"围观BOSS";
    [self.view addSubview:self.tableView];
    self.tableView.estimatedSectionHeaderHeight = 270;
    self.tableView.rowHeight = 73;
    [self.tableView registerNib:[UINib nibWithNibName:@"CJCommissionCell" bundle:nil] forCellReuseIdentifier:@"CJCommissionCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CJCommissionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJCommissionCell" forIndexPath:indexPath];
    
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"CJCommissionRankCell" owner:nil options:nil].firstObject;
    }
    CJCommissionModel *model = self.listArray[indexPath.row];
    [cell setModel:model];
  //  cell.rankLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                           style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}


@end
